<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
        .layui-layer-btn1 {
            background-color: red !important;
            color: #ffffff !important;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <fieldset class="layui-elem-field">
        <legend>提供礼品商家审核</legend>
        <div class="layui-field-box">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">商家信息</label>
                            <div class="layui-input-inline">
                                <input type="text" name="info" placeholder="请输入商家昵称或手机号" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <select name="status">
                                    <option value="">选择状态</option>
                                    <option value="0">待审核</option>
                                    <option value="1">审核通过</option>
                                    <option value="2">审核拒绝</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <table id="demo" lay-filter="demo"></table>
                    <script type="text/html" id="status">
                        {{# if (d.status == 0){ }}
                        <button class="layui-btn layui-btn-xs layui-bg-orange">待审核</button>
                        {{# }else if(d.status == 1){ }}
                        <button class="layui-btn layui-btn-xs layui-bg-blue">已通过</button>
                        {{# }else if(d.status == 2){ }}
                        <button class="layui-btn layui-btn-xs layui-bg-red">已拒绝</button>
                        {{# }else{ }}
                        <button class="layui-btn layui-btn-xs layui-bg-red">代支付押金</button>
                        {{# } }}
                    </script>
                    <script type="text/html" id="table-content-list">
                        {{# if (d.status == 0){ }}
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="shenhe"><i class="layui-icon layui-icon-survey"></i>审核</a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </fieldset>

</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'useradmin', 'table'], function(){
        var $ = layui.$,
                form = layui.form,
                table = layui.table;

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('demo', {
                url: "{:url('User/provide_operate')}",
                where: field,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //执行渲染
        table.render({
            elem: '#demo',
            url: "{:url('User/provide_operate')}",
            method: 'post',
            cols: [[
                {field: 'uid', title: '商家昵称'},
                {field: 'phone', title: '商家手机'},
                {field: 'recruit', title: '招商业务员'},
                {field: 'name', title: '店铺名称'},
                {field: 'address', title: '商家地址'},
                {field: 'status', title: '状态', templet: "#status"},
                {fixed: 'right', title: '操作', width: 250, align:'center', toolbar: '#table-content-list'}
            ]],
            page: {
                limits: [10, 20, 30, 40, 50]
            }
        });

        //监听事件
        table.on('tool(demo)', function(obj){
            var id = obj.data.id;
            var layEvent = obj.event;
            if (layEvent === 'shenhe'){
                layer.open({
                    type: 2
                    ,title: '提供礼品商家审核'
                    ,content: '/admin/User/provide_shenhe/id/' + id
                    ,area: ['100%', '100%']
                    ,btn: ['审核', '拒绝']
                    ,btnAlign: 'c'
                    ,yes: function(index, layero){
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                    ,btn2: function(index, layero){
                        $.post("{:url('User/provide_jujue')}", {id:id}, function(e){
                            if (e == 1){
                                layer.msg('拒绝成功', {offset: ['30%', '40%']});
                                setTimeout(function () {
                                    table.reload('demo'); //重载表格
                                    parent.layer.close(index); //再执行关闭
                                }, 500)
                            }else{
                                layer.msg('拒绝失败', {offset: ['30%', '40%']});
                            }
                            return false;
                        });
                    }
                });
            }
        });
    });
</script>
</body>
</html>
